home *** CD-ROM | disk | FTP | other *** search
- {
- | StdMenu provides standard menu objects.
- }
- unit StdMenu;
-
- interface
-
- uses MacIntf, StdPoll;
-
- const
- { Standard File menu item numbers }
- NewItem = 1;
- OpenItem = 2;
- CloseItem = 3;
- { ------ }
- SaveItem = 5;
- SaveAsItem = 6;
- RevertItem = 7;
- { ------ }
- PageSetupItem = 9;
- PrintItem = 10;
- { ------ }
- QuitItem = 12;
-
- type
- {
- | MenuHdlr is the base object for all menus.
- | The Create method installs the menu at the end of
- | the menu bar. The Choose method should be overridden
- | with code to perform a menu choice.
- }
- MenuHdlr = object
- TheMenu : MenuHandle;
- procedure Create (RsrcID : Integer);
- procedure Choose (Choice : Integer);
- end;
-
- {
- | AppleMenuHdlr provides all the functionallity of
- | a standard Apple menu. It must be Setup with an
- | alert id for the About… message before Create is
- | called.
- }
- AppleMenuHdlr = object (MenuHdlr)
- AboutID : Integer;
- procedure Create (RsrcID : Integer); override;
- procedure Choose (Choice : Integer); override;
- procedure Setup (AlertID : Integer);
- end;
-
- {
- | StdFileMenuHdlr is a minimal File menu. The Choose
- | method can Close DA's and Quit.
- }
- StdFileMenuHdlr = object (MenuHdlr)
- procedure Choose (Choice : Integer); override;
- end;
-
- {
- | StdEditMenuHdlr is a minimal Edit menu. The Choose
- | method supports DA editing.
- }
- StdEditMenuHdlr = object (MenuHdlr)
- procedure Choose (Choice : Integer); override;
- end;
-
- { ----------------------------------------------------------------------- }
- implementation
-
- {
- | Generic Menu Handler
- }
- procedure MenuHdlr.Create (RsrcID : Integer);
- begin
- { Read in a standard menu resource.
- | Remember: Object variables are Handles! 'Self' is set only
- | as you enter the method, so HLock it if you call any
- | potential heap-scramblers! }
- HLock(Handle(Self));
- TheMenu := GetMenu (RsrcID);
- InsertMenu (TheMenu, 0);
- HUnlock(Handle(Self)) end;
-
- procedure MenuHdlr.Choose (Choice : Integer);
- begin end;
-
- {
- | Apple Menu Handler
- }
- procedure AppleMenuHdlr.Create (RsrcID : Integer);
- begin
- { Read in the Apple menu stub, and add DA's }
- HLock(Handle(Self));
- TheMenu := GetMenu (RsrcID);
- AddResMenu (TheMenu, 'DRVR');
- InsertMenu (TheMenu, 0);
- HUnlock(Handle(Self)) end;
-
- procedure AppleMenuHdlr.Choose (Choice : Integer);
- var
- AccName : Str255;
- AccNumber : integer;
- begin
- { Post alert or open DA }
- if Choice = 1
- then AccNumber := Alert (AboutID, NIL)
- else begin
- GetItem (TheMenu, Choice, AccName);
- AccNumber := OpenDeskAcc (AccName) end end;
-
- procedure AppleMenuHdlr.Setup (AlertID : Integer);
- begin
- AboutID := AlertID end;
-
- {
- | Standard File Menu
- }
- procedure StdFileMenuHdlr.Choose (Choice : Integer);
- var
- FrontWP : windowPeek;
- begin
- case Choice of
- NewItem : ;
- OpenItem : ;
- CloseItem : begin { If frontmost window is DA, close it. }
- FrontWP := windowPeek(frontWindow);
- if FrontWP^.windowKind < 0
- then CloseDeskAcc(FrontWP^.windowKind) end;
- SaveItem : ;
- SaveAsItem : ;
- RevertItem : ;
- PageSetupItem : ;
- PrintItem : ;
- QuitItem : Done := true;
- otherwise { nothing } end end;
-
- {
- | Standard Edit menu
- }
- procedure StdEditMenuHdlr.Choose (Choice : Integer);
- var
- Trash : Boolean;
- begin
- Trash := SystemEdit (Choice-1) end;
-
- end. { of StdMenu unit }